package com.tongguan.paypos.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tongguan.paypos.R;
import com.tongguan.paypos.utils.ToastUtils;

/**
 * Created by Joylive on 2016/12/18 .
 */

public class PullUpLoadListViewFooter extends LinearLayout {
    public enum State {
        LOADING,
        NOT_LOADING,
    }

    private Context mContext;

    public PullUpLoadListViewFooter(Context context) {
        this(context, null);
    }

    public PullUpLoadListViewFooter(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        mContext = context;
    }

    public void updateView(State state, String content) {
        if (state == State.LOADING) {
            mLoadingLinearLayout.setVisibility(View.VISIBLE);
            mNotLoadingLinearLayout.setVisibility(View.INVISIBLE);
            mLoadingLabel.setText(content);
        } else if (state == State.NOT_LOADING){
            mLoadingLinearLayout.setVisibility(View.GONE);
            mNotLoadingLinearLayout.setVisibility(View.VISIBLE);
//            mNotLoadingLabel.setText(content);//重新设置报错
        } else {
            // should never go here
        }
    }

    private LinearLayout mLoadingLinearLayout;
    private TextView mLoadingLabel;

    private LinearLayout mNotLoadingLinearLayout;
    private TextView mNotLoadingLabel;

    // pul in R.id.pul*** means "pull up load"
    private void init() {
        inflate(getContext(), R.layout.pul_listview_footer, this);
        mLoadingLinearLayout = (LinearLayout) findViewById(R.id.pulListViewFooter_loading);
        mLoadingLabel = (TextView) findViewById(R.id.pulListViewFooter_loadingLabel);
        mNotLoadingLinearLayout = (LinearLayout) findViewById(R.id.pulListViewFooter_notLoading);
        mNotLoadingLabel = (TextView) findViewById(R.id.pulListViewFooter_notLoadingLabel);
    }
}
